/*点击切换为点击量*/
$('#hitsSum').on('click', function () {
    $('#title').html('');
    $('#sum').html('');
    hitsSum();
})
/*点击切换为收藏量*/
$('#collectionCount').on('click', function () {
    $('#title').html('');
    $('#sum').html('');
    collectionCount();
})

/*收藏量*/
function collectionCount() {
    $.ajax({
        url: '/goodsTable/collectionSum',
        type: 'post',
        dataType: 'json',
        success: function (data) {
            var type = new Array();
            var count = new Array();
            var lists = data.data;
            $('#title').append("<td>商品类型</td>");
            $('#sum').append("<td>收藏量</td>");
            for (var i = 0; i < lists.length; i++) {
                $('#title').append("<td>" + lists[i].title + "</td>");
                $('#sum').append("<td>" + lists[i].countNum + "</td>");
                count.push(lists[i].countNum);
                type.push(lists[i].title);
            }
            echart(type, count, '收藏量');
        }
    });
};

/*点击量**/
hitsSum();
function hitsSum() {
    $.ajax({
        url: '/goodsTable/hitsSum',
        type: 'post',
        dataType: 'json',
        success: function (data) {
            console.log(data.data[0].countNum);
            var type = new Array();
            var count = new Array();
            var lists = data.data;
            $('#title').append("<td>商品类型</td>");
            $('#sum').append("<td>点击量</td>");
            for (var i = 0; i < lists.length; i++) {
                $('#title').append("<td>" + lists[i].title + "</td>");
                $('#sum').append("<td>" + lists[i].countNum + "</td>");
                count.push(lists[i].countNum);
                type.push(lists[i].title);
            }
            echart(type, count, '点击量');
        }
    });
}

/*初始化echarts表格*/
var myChar = echarts.init(document.getElementById('main'));
function echart(type, count, name) {
    var option = {
        legend: {
            show: true
        },
        yAxis: {
            type: 'value',
            position: 'left',
        },
        xAxis: {
            data: type
        },
        series: [
            {
                name: name,
                type: 'bar',
                data: count,
                markPoint: {
                    data: [
                        {type: 'max', name: 'Max'},
                        {type: 'min', name: 'Min'}
                    ]
                }
            }
        ]
    }
    myChar.setOption(option);
}

/*返回*/
function goBack() {
    parent.$('#recordLog').val($('#goodsStatistics').text());
    parent.before();
    return false;
}

